package com.iknow.activity;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.iknow.IKnow;
import com.iknow.data.MessageSesstion;
import com.iknow.db.IKnowDataBase;
import com.iknow.ui.model.SessionAdapter;
import com.iknow.view.widget.MyListView;
import com.iknow.xmpp.service.Contact;
import com.iknow.xmpp.service.Friend;

public class MessageActivity extends Activity
{
  private DialogInterface.OnClickListener DialogClickListener;
  private Button mBackButton;
  private Context mContext;
  private int mCurrentSelectIndex = 0;
  private MyListView mMsgListView;
  private TextView mTitleText;
  private SessionAdapter sessionAdapter;

  public MessageActivity()
  {
    this.DialogClickListener = new DialogInterface.OnClickListener(this)
    {
      public void onClick(, int paramInt)
      {
        switch (paramInt)
        {
        default:
        case -1:
        }
        while (true)
        {
          paramDialogInterface.dismiss();
          return;
          MessageSesstion localMessageSesstion = MessageActivity.access$0(this.this$0).getItem(MessageActivity.access$1(this.this$0));
          IKnow.mIKnowDataBase.deleteSession(localMessageSesstion.getRosterID());
          MessageActivity.access$0(this.this$0).deleteMsg(MessageActivity.access$1(this.this$0));
          MessageActivity.access$0(this.this$0).notifyDataSetChanged();
        }
      }
    };
  }

  private void showConfigDialog()
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
    MessageSesstion localMessageSesstion = this.sessionAdapter.getItem(this.mCurrentSelectIndex);
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = localMessageSesstion.getRosterName();
    String str = String.format("删除与%s的所有消息？", arrayOfObject);
    localBuilder.setTitle(2131361795);
    localBuilder.setMessage(str);
    localBuilder.setPositiveButton(2131361796, this.DialogClickListener);
    localBuilder.setNegativeButton(2131361797, this.DialogClickListener);
    localBuilder.setCancelable(true);
    localBuilder.show();
  }

  public boolean onContextItemSelected(MenuItem paramMenuItem)
  {
    this.mCurrentSelectIndex = ((AdapterView.AdapterContextMenuInfo)paramMenuItem.getMenuInfo()).position;
    showConfigDialog();
    return true;
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903104);
    this.mContext = this;
    this.mMsgListView = ((MyListView)findViewById(2131296466));
    registerForContextMenu(this.mMsgListView);
    this.mBackButton = ((Button)findViewById(2131296342));
    this.mBackButton.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        this.this$0.finish();
      }
    });
    findViewById(2131296344).setVisibility(8);
    this.mMsgListView.setOnItemClickListener(new AdapterView.OnItemClickListener(this)
    {
      public void onItemClick(, View paramView, int paramInt, long paramLong)
      {
        MessageSesstion localMessageSesstion = MessageActivity.access$0(this.this$0).getItem(paramInt);
        Friend localFriend = IKnow.mIKnowDataBase.getFriendInfo(localMessageSesstion.getRosterID());
        if (localFriend == null);
        while (true)
        {
          return;
          Intent localIntent = new Intent(this.this$0, XmppChatActivity.class);
          localIntent.putExtra("friend_jid", localFriend.getID());
          localIntent.putExtra("name", localFriend.getName());
          localIntent.putExtra("contact", new Contact(localFriend.getID()));
          this.this$0.startActivity(localIntent);
        }
      }
    });
  }

  public void onCreateContextMenu(ContextMenu paramContextMenu, View paramView, ContextMenu.ContextMenuInfo paramContextMenuInfo)
  {
    super.onCreateContextMenu(paramContextMenu, paramView, paramContextMenuInfo);
    paramContextMenu.add(getString(2131361917));
  }

  protected void onDestroy()
  {
    this.mMsgListView = null;
    this.sessionAdapter.clear();
    this.sessionAdapter = null;
    super.onDestroy();
  }

  public boolean onMenuOpened(int paramInt, Menu paramMenu)
  {
    return super.onMenuOpened(paramInt, paramMenu);
  }

  protected void onPause()
  {
    super.onPause();
  }

  protected void onResume()
  {
    super.onResume();
    this.sessionAdapter = new SessionAdapter(getLayoutInflater(), IKnow.mIKnowDataBase.getAllSessionMsg(), this);
    this.mMsgListView.setAdapter(this.sessionAdapter);
  }

  protected void onStart()
  {
    super.onStart();
  }

  protected void onStop()
  {
    super.onStop();
  }

  public void openContextMenu(View paramView)
  {
    super.openContextMenu(paramView);
  }
}